package com.cruise.biztest1.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codingapi.txlcn.tc.annotation.DTXPropagation;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.cruise.biztest1.mapper.LcnDemoMapper;
import com.cruise.biztest1.service.LcnDemoService;
import com.cruise.biztest2.api.feign.FeignBiztest2Api;
import com.cruise.biztest2.api.pojo.entity.LcnDemo;
import com.cruise.biztest2.api.pojo.entity.LcnDemo2;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 彭闯
 * @since 2021-01-23
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class LcnDemoServiceImpl extends ServiceImpl<LcnDemoMapper, LcnDemo> implements LcnDemoService {


    @Resource
    private  LcnDemoMapper lcnDemoMapper;

    @Resource
    private FeignBiztest2Api feignBiztest2Api;


    /**
     * 分布式事务注解 发起方REQUIRED， 参与方 SUPPORTS
     * @param lcnDemo
     */
    @LcnTransaction(propagation = DTXPropagation.REQUIRED)
    @Override
    public void addLcnDemo(LcnDemo lcnDemo) {
        lcnDemoMapper.insert(lcnDemo);

        LcnDemo2 lcnDemo2 = new LcnDemo2();
        lcnDemo2.setId(1);
        lcnDemo2.setModule("lcnDemo2");
        lcnDemo2.setName("cruise");
        feignBiztest2Api.addLcnDemo2(lcnDemo2);
    }
}
